<?php
class MemberAction extends AccountAction {
	function index()
	{		
		$this->display();
	}
	
	/**
	 * 密码修改
	 */
	function changepw()
	{
		$oldpass=trim($_REQUEST['oldpassword']);
		$newpass=trim($_REQUEST['newpassword']);

		$m=D("User");
		$m->find(getMemberId());
		if($m->password==md5($oldpass))
		{
			$m->password=md5($newpass);
			$m->save();
			$this->ajaxReturn("","密码已更新",1);
		}
		else {
			$this->ajaxReturn("","旧密码错误",0);
		}
	}
	
	function baby()
	{
		$act=isset($_REQUEST['act'])?trim($_REQUEST['act']):"add";//:isset($_REQUEST['Id'])?"edit":"add";
		$_GET['act']=$act;
		//echo $act;
		switch ($act)
		{
			case 'add':
				if(!$this->isPost()){
					$this->display();
				}else{
					$m=D("Baby");
					//echo "asdfasd";
					if($m->create()){
						$id=$m->add();
						if($id)
						{
							$this->redirect("/Member/baby/act/edit/Id/".$id);
						}
						else
						{
							die("DBERROR:".$m->getDbError());
						}
					}else{
						die("ERROR:".$m->getError());
					}
				}
				break;
			case 'edit':
				if(!$this->isPost())
				{
					$this->assign('data',getBabyById(intval($_REQUEST['Id'])));
					$this->display();
				}
				else
				{
					$m=D("Baby");
					if($m->create())
					{
						$m->updatetime=getFormatTime();
						$rows=$m->save();
						$this->redirect("/Member/baby/act/edit/Id/".$_REQUEST['Id']);
					}
					else 
					{
						die($m->getError());
					}
				}
				
		}
	}
}